(function(obj) {
var token = 'da44638a-c0ea-4626-ae99-5d28ca49e573';
	var host = window.location.host+"/im-web/socket?xAuthToken="+token;
	ws.init({
		url: "ws://"+host 
	                 // 后台接口地址
	}).connect();
	
	var delaytime = 30000;
	timename=setTimeout(ws.onclose,delaytime);

		ws.onopen = function () {
		ws.send("测试连接*true开始");
		};
		ws.onmessage = function (event) {
			delaytime = 30000;
		}

		ws.onclose = function () {
		};
		ws.onerror = function () {
		};
	
	
	
	
	
	
	
	var msg;
	ws.onmessage = receiveMessage;
	function receiveMessage(event){
		var data =  eval('(' + event.data + ')');
		console.log(data);
		msg = data
		$("#textvalue").append(event.data+"<br/>");
		var serid = data.message.id;
		$.ajax({
			  type: 'POST',
			  url: '/im-web/im/receiptMessage',
			  traditional: true,
			  data: {
				  msgId:serid,
				  xAuthToken:token
			  },
			  success: function(data){
				  console.log(data);
			  }
		});
	}
	
	obj.msg = function() {
		alert(msg)
	}
	
	
	obj.sendMsg = function(to,content,clientid,type) {
		$.ajax({
			  type: 'POST',
			  url: '/im-web/im/sendMessage',
			  traditional: true,
			  data: {
				  to:to,
				  content:content,
				  clientid:clientid,
				  type:type,
				  xAuthToken:token
			  },
			  success: function(data){
				  console.log(data);
			  }
		});
	}
	obj.sendgroupMsg = function(to,content,clientid,type) {
		$.ajax({
			type: 'POST',
			url: '/im-web/im/sendMessages',
			traditional: true,
			data: {
				to:to,
				content:content,
				clientid:clientid,
				type:type,
				xAuthToken:token
			},
			success: function(data){
				console.log(data);
			}
		});
	}
})(webs = {});